import random
import tkinter as tk

# 国庆小知识问答
quiz_questions = [
    {"question": "中华人民共和国成立于哪一年？", "answer": "1949"},
    {"question": "国庆节是每年的几月几日？", "answer": "10 月 1 日"},
    {"question": "五星红旗的设计者是谁？", "answer": "曾联松"}
]

class QuizApp:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("国庆小知识问答与祝福语生成器")
        self.question_index = 0
        self.create_widgets()

    def create_widgets(self):
        self.question_label = tk.Label(self.root, text="", wraplength=300)
        self.question_label.pack(pady=10)

        self.answer_entry = tk.Entry(self.root)
        self.answer_entry.pack(pady=5)

        self.check_button = tk.Button(self.root, text="检查答案", command=self.check_answer)
        self.check_button.pack(pady=5)

        self.result_label = tk.Label(self.root, text="", fg="green")
        self.result_label.pack(pady=5)

        self.start_button = tk.Button(self.root, text="开始问答", command=self.start_quiz)
        self.start_button.pack(pady=10)

        self.wish_label = tk.Label(self.root, text="", wraplength=300)
        self.wish_label.pack(pady=10)

        self.generate_button = tk.Button(self.root, text="生成祝福语", command=self.generate_wish)
        self.generate_button.pack(pady=5)

    def check_answer(self):
        user_answer = self.answer_entry.get()
        current_question = quiz_questions[self.question_index]
        if user_answer == current_question["answer"]:
            self.result_label.config(text="正确！")
        else:
            self.result_label.config(text="错误。正确答案是：" + current_question["answer"])
        self.answer_entry.delete(0, tk.END)
        self.question_index += 1
        if self.question_index < len(quiz_questions):
            self.question_label.config(text=quiz_questions[self.question_index]["question"])
        else:
            self.question_label.config(text="问答环节结束。")
            self.start_button.config(state=tk.NORMAL)
            self.check_button.config(state=tk.DISABLED)

    def start_quiz(self):
        self.question_index = 0
        self.start_button.config(state=tk.DISABLED)
        self.check_button.config(state=tk.NORMAL)
        self.question_label.config(text=quiz_questions[self.question_index]["question"])
        self.result_label.config(text="")

    def generate_wish(self):
        wishes = [
            "祖国华诞，繁荣昌盛，愿祖国的明天更加灿烂辉煌！",
            "国庆佳节，祝福祖国山河壮丽，人民幸福安康！",
            "在这个特殊的日子里，祝愿伟大的祖国永远年轻，充满活力！"
        ]
        self.wish_label.config(text=random.choice(wishes))

    def run(self):
        self.root.mainloop()

app = QuizApp()
app.run()